package controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import beans.UserVO;

@Controller
public class HomeHolaMundoController {

	@RequestMapping(value="public/home", method = RequestMethod.GET)
	public ModelAndView home(){
		ModelAndView mv = new ModelAndView("home");

		return mv;
	}
	
//	@RequestMapping(value="public/login", method = RequestMethod.GET)
//	public ModelAndView loginController(@ModelAttribute UserVO userVO){
//		
//		System.out.println("Entre al login bien");
//		String user = "Xino";
//		String pass = "123";
//		ModelAndView mv = new ModelAndView();
//		
//		if(userVO.getName().equals(user) && userVO.getPassword().equals(pass)) {
//			mv.setViewName("hola");
//			mv.addObject("paramUser", userVO.getName()); //Estoy metiendo en la request un valor para paramUser
//			mv.addObject("user", userVO);
//		}
//		else
//		{
//			mv.setViewName("error");
//		}
//		return mv;
//	}
	
	@RequestMapping(value="public/login", method = RequestMethod.GET)
	public ModelAndView loginController(@ModelAttribute UserVO userVO){
		
		System.out.println("Entre al login bien");
		String user = "Xino";
		String pass = "123";
		ModelAndView mv = new ModelAndView();
		
		if(userVO.getName().equals(user) && userVO.getPassword().equals(pass)) {
			mv.setViewName("elegirAccion");
			mv.addObject("user", userVO);
		}
		else
		{
			mv.addObject("errorParam", "Error de logueo, usuario o contrasenia incorrecto.");
			mv.setViewName("error");
		}
		return mv;
	}
	
	@RequestMapping(value="public/backHome", method = RequestMethod.GET)
	public ModelAndView backHome(){
		ModelAndView mv = new ModelAndView("home");
		return mv;
	}
}
